package com.hzhr.iot.meterplan.controller;

import com.hzhr.iot.core.annotation.ApiImplicitInternalParams;
import com.hzhr.iot.core.annotation.Author;
import com.hzhr.iot.core.dto.ResponseExceptionDto;
import com.hzhr.iot.core.exception.ServiceException;
import com.hzhr.iot.meterplan.controller.base.BaseController;
import com.hzhr.iot.meterplan.model.meterPlan_meterGasUser.MeterPlan_MeterGasUserGetModel;
import com.hzhr.iot.meterplan.model.meterPlan_meterGasUser.MeterPlan_MeterGasUserPostModel;
import com.hzhr.iot.meterplan.model.meterPlan_workOrder.MeterPlan_workOrderGetModel;
import com.hzhr.iot.meterplan.model.meterPlan_workOrder.MeterPlan_workOrderModel;
import com.hzhr.iot.meterplan.service.MeterPlan_MeterGasUserService;
import com.hzhr.iot.meterplan.service.MeterPlan_WorkOrderService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.Map;

@Api(tags = "MeterPlan_MeterGasUser", description = "抄表计划下的抄表用户")
@RestController
@RequestMapping(value = "")
public class MeterPlan_MeterGasUserController extends BaseController {
    @Autowired
    MeterPlan_MeterGasUserService meterPlan_meterGasUserService;

    //region /meter-plans/{meterPlanId}/work-orders POST
    //region swagger响应码 : post
    @ApiResponses({
            @ApiResponse(code = 200, message = "成功"),
            @ApiResponse(code = 403, message = "----异常代码 : 202  \n----异常类型 : 业务流程异常  \n----异常业务 : 查询抄表计划状态  \n----异常说明 : 只有非执行中的抄表计划才能加入或移除用户  \n\n----异常代码 : 201  \n----异常类型 : 业务流程异常  \n----异常业务 : 查询抄表计划  \n----异常说明 : 抄表计划不存在  \n\n", response = ResponseExceptionDto.class),
    })
    //endregion
    //region swagger说明 : post
    @ApiOperation(value="创建抄表计划下的抄表用户", notes="创建抄表计划下的抄表用户  \n1.查询抄表计划，如果抄表计划不存在，抛出异常  \n2.如果抄表计划的状态为执行中，抛出异常“该抄表计划正在执行中，无法加入或移除用户”  \n3.将addCodes所对应的燃气用户加入抄表计划中  \n这些要加入的燃气用户必须满足以下规则，才允许加入到抄表计划：  \n如果燃气用户在某个抄表计划下，那么该抄表计划的状态不能为“执行中”  \n4.如果delCodes所对应的燃气用户在该抄表计划下，则将这些燃气用户从这些抄表计划下移除  \n5.返回信息  \n",produces = "application/json")
    //endregion
    //region swagger参数 : post
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "令牌",required = true, dataType = "string", paramType = "header"),

            @ApiImplicitParam(name = "meterPlanId", value = "抄表计划id",required = true, dataType = "string", paramType = "path"),

            @ApiImplicitParam(name = "show", value = "展示形式 one:展示一个,list:展示列表,null(空值):不展示", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "show_info", value = "是否展示详情", defaultValue = "false", required = false, dataType = "boolean", paramType = "query"),
            @ApiImplicitParam(name = "page", value = "页数", defaultValue = "1",required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "count", value = "每页数量", defaultValue = "1",required = false, dataType = "int", paramType = "query"),

    })
    @ApiImplicitInternalParams({
            @ApiImplicitParam(name = "_token", value = "令牌",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-id", value = "用户编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-code", value = "用户代码",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-name", value = "用户名",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-company-id", value = "公司编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-dept-id", value = "部门编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-type", value = "用户类型(关联: common_service.options.code, typeCode = 'USER_TYPE')",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-transaction-id", value = "交易流水号",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-transaction-type", value = "交易类型",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-access-mode", value = "访问模式 0:一般 1:全局",defaultValue = "0", required = false, dataType = "int", paramType = "header"),

            @ApiImplicitParam(name = "_page", value = "页数", defaultValue = "1",required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "_count", value = "每页数量", defaultValue = "1",required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "_show", value = "展示形式 one:展示一个,list:展示列表,null(空值):不展示", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "_show_info", value = "是否展示详情", defaultValue = "false", required = false, dataType = "boolean", paramType = "query"),

    })
    //endregion
    //region 请求 : post
    @RequestMapping(value = "/meter-plans/{meterPlanId}/meter-gas-users", method = RequestMethod.POST)
    //endregion
    @Author
    public ResponseEntity<MeterPlan_MeterGasUserGetModel> post(@PathVariable("meterPlanId") String meterPlanId,
                                                               @RequestParam @ApiIgnore Map<String, Object> query,
                                                               @RequestBody MeterPlan_MeterGasUserPostModel body) throws ServiceException {
        MeterPlan_MeterGasUserGetModel responseBody = meterPlan_meterGasUserService.post(initHeader(),meterPlanId,query,body);
        return new ResponseEntity<>(responseBody, HttpStatus.OK);
    }
    //endregion
}




